/**
 * @description 抽象服务工厂
 * @author 钟宇飞
 * @version 1.0。0
 */

const path = require('path');
const fs = require('fs');

/**
 * @typedef ServiceFactoryType
 * @property {import("../service/RoomInfoService.js")} roomInfoService
 * @property {import("../service/AdminInfoService.js")} adminInfoService
 * @property {import("../service/StuInfoService.js")} stuInfoService
 * @property {import("../service/AreaService.js")} areaService
 */

/**
 * @type {ServiceFactoryType}
 */
const ServiceFactory = (() => {
  let obj = {};
  let arr = fs.readdirSync(path.join(__dirname, '../service'));
  for (let item of arr) {
    let properyName = item.replace('.js', '').replace(/^[A-Z]/, p => p.toLowerCase());
    let temp = require(path.join(__dirname, '../service', item));
    if (typeof temp === 'function') {
      obj[properyName] = Reflect.construct(temp, []);
    }
  }
  return Object.freeze(obj);
})();

module.exports = ServiceFactory;
